﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PetroMentor.Service.Manager;
using PetroMentor.Service.Entities;
using PetroMentor.Service.Common;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace PetroMentor.Service
{
    /// <summary>
    /// AddHandler 的摘要说明
    /// </summary>
    public class SaveHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            CommonSaveInfo<T_WHYL_AQXS,T_WHYL_ATTACHMENT> obj = new CommonSaveInfo<T_WHYL_AQXS,T_WHYL_ATTACHMENT>();
            string str = SerializeManager.StreamToString(context.Request.InputStream);
            CommonSaveInfo<T_WHYL_AQXS,T_WHYL_ATTACHMENT> result = JsonConvert.DeserializeObject<CommonSaveInfo<T_WHYL_AQXS, T_WHYL_ATTACHMENT>>(str, new JavaScriptDateTimeConverter());




            //string module = context.Request.Form[Consts.MODULE];
            //string attachement = context.Request.Form[Consts.ATTACHEMENT_MODULE];
            //string modulecontent = context.Request.Form[Consts.MODULECONTENT];
            //string attachementcontent = context.Request.Form[Consts.ATTACHMENTCONTENT];
            //string optype = context.Request.Form[Consts.OP_TYPE];

            //string saveresult = SerializeManager.SerializeSaveEntity(module, attachement, modulecontent, attachementcontent, optype);

            string saveresult = SerializeManager.SerializeSaveEntity<T_WHYL_AQXS, T_WHYL_ATTACHMENT>(result);

            context.Response.ContentType = "text/plain";
            context.Response.Write(saveresult);
        }              

       public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}